<?php

namespace Plugin\Alarm\Event;

use Common\Common;
use Plugin\Organization\Repository\RdOrganizeUserStandRepository;

class WorkCreatedEvent extends AbstractWorkHandleEvent
{
    public array $work;
    public int $standId;
    public int $userId;
    public function __construct($work, $standId, $userId) {
        $this->work = $work;
        $this->standId = $standId;
        $this->userId = $userId;
    }

    public function getTitle(): string
    {
        return '工单创建';
    }

    public function getTargetUsers(): array
    {
        // 获取站点管理员
        try {
            $users = Common::container()->get(RdOrganizeUserStandRepository::class)->getStandUsers($this->standId, 1);
        } catch (\Throwable $e) {
            Common::logException(__CLASS__, $e);
            $users = [];
        }

        $users[] = $this->userId;
        return $users;
    }

    public function getMessage(): string
    {
        return '#' . $this->work['id'] . ' ' . $this->work['title'] . '工单已创建';
    }
}